import 'bootstrap/dist/css/bootstrap.css';
import '../css/style.scss';
import {config,qrcode,queryOrder_new,log} from './urlconfig/config.js';
$('.nav-all a[href="index.html"]').addClass('active');
require('./common.js');
require('./swiper.min.js');
var Fingerprint = require('./fingerprint.js');
var token;
var edition='web_1.5.1.2';
var channel;
var sys='Window10';
if(localStorage.token != null){
    token=localStorage.token
}
var cpuid = new Fingerprint().get();
function GetUrlParam(paraName) {
    var url = document.location.toString();
    var arrObj = url.split("?");
    if (arrObj.length > 1) {
        var arrPara = arrObj[1].split("&");
        var arr;

        for (var i = 0; i < arrPara.length; i++) {
            arr = arrPara[i].split("=");

            if (arr != null && arr[0] == paraName) {
                return arr[1];
            }
        }
        return "";
    }
    else {
        return "";
    }
};

(function (){
    var url = document.location.toString();
    if (url.indexOf("?") != -1) {
        channel=GetUrlParam("c_code");
        localStorage.setItem("channel",channel);
    }else{
        if(localStorage.channel !=null){
            channel=localStorage.getItem("channel");
        }else{
            channel='plat_a01';
        }
    }
})();
$(function (){
    $(".close-btn").click(function (){
        $(".close-office").show();
    });
    $(".quxiao").click(function (){
        $(".close-office").hide();
    });
});
$('#myModal').on('hide.bs.modal', function (e) {
    $(".close-office").hide();
});
$(".btnLayer").click(function (){
    var tablog=$(this).attr("data-log");
    if(localStorage.token==null){
        var shows=$(this).attr("data-token");
        localStorage.setItem('data',shows);
        $('#login').modal('show');
    }else{
            var pro=$(this).attr("data-token");
            $('#myModal').modal('show');
            getEwm(pro);
            if(pro=='bb6d01050605000fba16597e6dc5ae28'){
                $("#model-tab-office .tab2").click()
            }else if(pro=='02804067beae3da1faa4ff72edf33f20'){
                $("#model-tab-office .tab3").click()
            }else if(pro=='b85141e007ea742bb705f6960b7d57b0'){
                $("#model-tab-office .tab4").click()
            }else if(pro=='d478dab8d97845c5b6638f95f8a713ac'){
                $("#model-tab-office .tab1").click()
            }else if(pro=='1274c85c9791c16dca2ff87dd927317e'){
                $("#model-tab-office .tab5").click()
            }
            else{

            }
    }
});

var ref=document.referrer;
if(ref.indexOf("test.office.web.zhuazi.com") !=-1){
    if(localStorage.token==null){
        $('#login').modal('show');
    }else{
        var btn=$(this).attr("data-log");
        $('#myModal').modal('show');
        var pro="bb6d01050605000fba16597e6dc5ae28";
        getEwm(pro);
    }
    window.location.href="http://office.store.zhuazi.com/channel/MicrosoftOfficeV3.3.2.13.X86.zh_CN_InstallationComponent_zywz_a03.exe"
}else{

}

function getEwm(pro){
    $.ajax({
        type:'post',
        url:qrcode,
        dataType:'json',
        data:{
            token:token,
            product_token:pro,
            channel:channel,
            buy_position:'website',
            two_purchase:1
        },
        success:function (res){
            if(res.code === 200) {
                $(".center_ewm").remove();
                var $img= '<img src="'+res.data.url+'" class="center_ewm">';
                $('.center-ewm').prepend($img);
                window.localStorage.removeItem('data');
            }
        },
        error:function (err){
            console.log(err)
        }
    });
}

$("#model-tab-office .tab-content").click(function (){
    window.localStorage.removeItem('data');
    var data=$(this).attr("data-id");
    $(this).siblings().removeClass("selected");
    $(this).addClass("selected");
    var pro=$(this).attr("data-token");
    getEwm(pro);
    if(data==1){
        $(".model-tab-bc").addClass("model-tab-bc-1");
        $(".model-tab-bc").removeClass("model-tab-bc-2");
        $(".model-tab-bc").removeClass("model-tab-bc-3");
        $(".model-tab-bc").removeClass("model-tab-bc-4");
        $(".model-tab-bc").removeClass("model-tab-bc-5");
        pageShow('payWindow',' payProPageShow')

    }else if(data==2){
        $(".model-tab-bc").addClass("model-tab-bc-2");
        $(".model-tab-bc").removeClass("model-tab-bc-1");
        $(".model-tab-bc").removeClass("model-tab-bc-3");
        $(".model-tab-bc").removeClass("model-tab-bc-4");
        $(".model-tab-bc").removeClass("model-tab-bc-5");
        pageShow('payWindow','payFamilyPageShow')
    }
    else if(data==3){
        $(".model-tab-bc").addClass("model-tab-bc-3");
        $(".model-tab-bc").removeClass("model-tab-bc-1");
        $(".model-tab-bc").removeClass("model-tab-bc-2");
        $(".model-tab-bc").removeClass("model-tab-bc-4");
        $(".model-tab-bc").removeClass("model-tab-bc-5");
        pageShow('payWindow','payPersonPageShow')
    }
    else if(data==4){
        $(".model-tab-bc").addClass("model-tab-bc-4");
        $(".model-tab-bc").removeClass("model-tab-bc-1");
        $(".model-tab-bc").removeClass("model-tab-bc-2");
        $(".model-tab-bc").removeClass("model-tab-bc-3");
        $(".model-tab-bc").removeClass("model-tab-bc-5");
        pageShow('payWindow','pay2016PageShow')
    }else if(data==5){
        $(".model-tab-bc").addClass("model-tab-bc-5");
        $(".model-tab-bc").removeClass("model-tab-bc-1");
        $(".model-tab-bc").removeClass("model-tab-bc-2");
        $(".model-tab-bc").removeClass("model-tab-bc-3");
        $(".model-tab-bc").removeClass("model-tab-bc-4");
    }else{

    }
});

var interval2;
$('#myModal').on('shown.bs.modal', function (e) {
    interval2 = setInterval(function () {
        $.ajax({
            type:'post',
            url:queryOrder_new,
            dataType:'json',
            data:{
                token:token
            },
            success:function (res){
                if(res.code == 200) {
                    $('#myModal').modal('hide');
                    pageShow('windowDesktop','buySuccess');
                    window.location.href="/course.html";
                    clearInterval(interval2);
                }else{

                }
            },
            error:function (err){
                console.log(err)
            }
        })
    },2000)

});


function tab(btn,boolen){
    $.ajax({
        type:'GET',
        url:log+ btn +'/'+ channel+'/'+ edition +  '/'+ sys + '/'+cpuid,
        dataType: 'json',
        async:boolen,
        success:function(res) {
            if(res.code==200){

            }
        },
        error:function(err) {
            console.log(err)

        }
    })

}
var man=$("#fagepage").val();
pageShow(man,"pageShow");
/*页面显示日志*/

function pageShow(name,pageShow){
    $.ajax({
        type:'GET',
        url:log+ name+'/'+pageShow +'/'+ channel+'/'+ edition + '/'+ sys + '/'+cpuid,
        dataType: 'json',
        success:function(res) {
            if(res.code==200){

            }else{

            }
        },
        error:function(err) {
            console.log(err)
        }
    });
}
$(".muban").click(function (){
    var btn=$(this).attr("data-log");
    tab(btn,true)
});

/*office点击日志*/
$(".office-background2 .btnLayer").click(function (){
    var btnLog=$(this).attr("data-log");
    tab(btnLog,true);
});
$(".baotu").click(function (){
    var tablog=$(this).attr("data-log");
    tab(tablog,true);
});
$(".bntclose").click(function(){
    var tablog=$(this).attr("data-log");
    tab(tablog,true);
});

$(function(){
    if (localStorage.getItem("data") != null) {
        $('#myModal').modal('show');
        var pro=localStorage.getItem("data");
        if(pro=='bb6d01050605000fba16597e6dc5ae28'){
            $("#model-tab-office .tab2").click()
        }else if(pro=='02804067beae3da1faa4ff72edf33f20'){
            $("#model-tab-office .tab3").click()
        }else if(pro=='b85141e007ea742bb705f6960b7d57b0'){
            $("#model-tab-office .tab4").click()
        }else if(pro=='d478dab8d97845c5b6638f95f8a713ac'){
            $("#model-tab-office .tab1").click()
        }else if(pro=='1274c85c9791c16dca2ff87dd927317e'){
            $("#model-tab-office .tab5").click()
        }
        else{

        }
    }else {


    }
});

$('#myModal').on('hide.bs.modal', function (e) {
    window.localStorage.removeItem('data');
    clearInterval(interval2);
});
